package gold.gold04;

/**
 *
 */
public class S1615珠玑妙算 {
    /**
     * 100, 因为只有四种情况, 练习一下switch操作。
     * 这题solution长度就只有4, 意义不大。时间都是0。
     */
    public int[] masterMind(String solution, String guess) {
        // 统计每个字符存在的次数
        char[] solArr = solution.toCharArray();
        char[] gueArr = guess.toCharArray();
        int match = 0;
        for(int i = 0; i < solArr.length; i++){
            if(solArr[i] == gueArr[i])
                match++;
        }

        int[][] numCount = new int[4][2];
        for(int i = 0; i < solArr.length; i++){
            switch(solArr[i]){
                case 'R' -> numCount[0][0]++;
                case 'Y' -> numCount[1][0]++;
                case 'G' -> numCount[2][0]++;
                case 'B' -> numCount[3][0]++;
                default -> System.out.println("error");
            }
            switch(gueArr[i]){
                case 'R' -> numCount[0][1]++;
                case 'Y' -> numCount[1][1]++;
                case 'G' -> numCount[2][1]++;
                case 'B' -> numCount[3][1]++;
                default -> System.out.println("error");
            }
        }
        int fakeMatchPlus = 0;
        for(int[] temp1: numCount){
            fakeMatchPlus += Math.min(temp1[0], temp1[1]);
        }
        int[] res = new int[2];
        res[0] = match;
        res[1] = fakeMatchPlus - match;
        return res;
    }
}
